<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CustomerResource\Pages;
use App\Filament\Resources\CustomerResource\RelationManagers;
use App\Models\Customer;
use Filament\Forms;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class CustomerResource extends Resource
{
    protected static ?string $model = Customer::class;
    protected static ?string $navigationLabel = '客户管理';
    protected static ?string $navigationIcon = 'heroicon-o-user-group';
    protected static ?int $navigationSort = 1;

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('customer_name')->required()->label('客户姓名'),
                TextInput::make('email')->email()->required()->label('邮箱'),
                TextInput::make('mobile')->tel()->required()->label('手机号'),
                TextInput::make('address')->required()->label('地址'),
                TextInput::make('city')->required()->label('城市'),
                TextInput::make('zip_code')->required()->label('邮编'),
                TextInput::make('country')->required()->label('国家'),
                Radio::make('active')->required()->label('状态')->options([0 => '禁用', 1 => '启用'])->default(1),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('customer_name')->label('客户姓名')->description('这就是客户姓名，不要干别的用'),
                TextColumn::make('email')->label('邮箱'),
                TextColumn::make('mobile')->label('手机号'),
                TextColumn::make('address')->label('地址')->limit(30),
                TextColumn::make('city')->label('城市'),
                TextColumn::make('zip_code')->label('邮编'),
                TextColumn::make('country')->label('国家'),
                TextColumn::make('active')->label('状态'),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ViewAction::make(),
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListCustomers::route('/'),
            'create' => Pages\CreateCustomer::route('/create'),
            'view' => Pages\ViewCustomer::route('/{record}'),
            'edit' => Pages\EditCustomer::route('/{record}/edit'),
        ];
    }
}
